home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / SmallTalk / Magnitude.st < prev    next >
Text File  |  1995-08-25  |  2KB  |  95 lines

  1. "======================================================================
  2. |
  3. |   Magnitude Method Definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbb         16 Mar 91      Class creation now separate statement.
  34. |
  35. | sbyrne     25 Apr 89      created.
  36. |
  37. "
  38.  
  39. Object subclass: #Magnitude
  40.        instanceVariableNames: ''
  41.        classVariableNames: ''
  42.        poolDictionaries: ''
  43.        category: nil
  44. !
  45.  
  46. Magnitude comment: 
  47. 'I am an abstract class.  My objects represent things that are discrete and 
  48. map to a number line.  My instances can be compared with < and >.' !
  49.  
  50. !Magnitude methodsFor: 'basic'!
  51.  
  52. "Relational operators.  '==', '~=', '~~' are inherited from Object"
  53.  
  54. = aMagnitude
  55.     self subclassResponsibility
  56. !
  57.  
  58. < aMagnitude
  59.     self subclassResponsibility
  60. !
  61.  
  62. > aMagnitude
  63.     self subclassResponsibility
  64. !
  65.  
  66. <= aMagnitude
  67.     ^(self < aMagnitude) | (self = aMagnitude)
  68. !
  69.  
  70. >= aMagnitude
  71.     ^(self > aMagnitude) | (self = aMagnitude)
  72. !!
  73.  
  74.  
  75.  
  76. !Magnitude methodsFor: 'misc methods'!
  77.  
  78. between: min and: max
  79.     "Returns true if object is inclusively between min and max."
  80.     ^(self >= min) and: [ self <= max ]
  81. !
  82.  
  83. min: aMagnitude
  84.     self < aMagnitude ifTrue: [ ^self ]
  85.                       ifFalse: [ ^aMagnitude ]
  86. !
  87.  
  88. max: aMagnitude
  89.     self > aMagnitude ifTrue: [ ^self ]
  90.                       ifFalse: [ ^aMagnitude ]
  91. !!
  92.  
  93.